﻿namespace TC
{
    public class Service_tree : TranslateTree
    {
        public override editor.cfg.behaviourtree.TreeNode OnTranslate(Node node)
        {
            Service t = node as Service;
            editor.cfg.behaviourtree.Service re = new editor.cfg.behaviourtree.Service();
            re.id = t.id;

            Port p = t.graph.GetConnect(t.start);
            if (p == null)
            {
                re.onBegin = -1;
            }
            else
            {
                re.onBegin = p.parent.id;
            }

            p = t.graph.GetConnect(t.update);
            if (p == null)
            {
                re.onTick = -1;
            }
            else
            {
                re.onTick = p.parent.id;
            }

            p = t.graph.GetConnect(t.stop);
            if (p == null)
            {
                re.onEnd = -1;
            }
            else
            {
                re.onEnd = p.parent.id;
            }

            p = t.graph.GetConnect(t.out0);
            if(p == null)
            {
                re.node = null;
            }
            else
            {
                re.node = BTGraphExport.translate[p.parent.GetType()].OnTranslate(p.parent);
            }

            return re;
        }
    }
}
